package com.example.databindingdemo.activity;

import android.os.Bundle;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.LinearLayoutManager;

import com.example.databindingdemo.R;
import com.example.databindingdemo.adapter.RecyclerViewAdapter;
import com.example.databindingdemo.databinding.ActivityRecyclerBindingAdapterBinding;
import com.example.databindingdemo.viewmodel.RecyclerViewViewModel;

/**
 * @author: njb
 * @date: 2022/9/18 17:26
 * @desc:
 */
public class RecyclerViewActivity extends AppCompatActivity {
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        initView();
    }

    private void initView() {
        ActivityRecyclerBindingAdapterBinding recyclerBindingAdapterBinding = DataBindingUtil.setContentView(this, R.layout.activity_recycler_binding_adapter);
        recyclerBindingAdapterBinding.recyclerView.setHasFixedSize(true);
        RecyclerViewAdapter adapter = new RecyclerViewAdapter(new RecyclerViewViewModel().getBooks());
        recyclerBindingAdapterBinding.recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recyclerBindingAdapterBinding.recyclerView.setAdapter(adapter);
    }
}
